﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:calc="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:pi="clr-namespace:PillBox.Interactivity;assembly=PillBox.Interactivity"
    x:Class="PillBox.Client.Views.ScheduleDayView"
    mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="480"
    d:DataContext="{d:DesignData ../SampleData/ScheduleDayViewModelSampleData.xaml}">
    <UserControl.Resources>

        <Style x:Key="Local_PlainButton" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <ContentPresenter/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <DataTemplate x:Key="Local_ScheduleDayItemViewModelTemplate">
            <Button
                calc:Click.Command="{Binding MedicationCommand}"
                Style="{StaticResource Phone_TiltingButtonBase}"
                Margin="0,0,18,0">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                    	<RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <StackPanel
            			HorizontalAlignment="Left"
            			Grid.ColumnSpan="2"
            			Orientation="Horizontal"
                        Height="27"
                        VerticalAlignment="Top"
                        Margin="0,5,0,0"/>
                    <!-- color and name -->
                    <StackPanel
            			Grid.Column="1"
            			HorizontalAlignment="Left"
            			Orientation="Horizontal"
            			VerticalAlignment="Top">
                        <CheckBox
            				IsChecked="{Binding IsTaken, Mode=TwoWay}"
                            IsEnabled="{Binding DataContext.AllowEditing, ElementName=LayoutRoot}"
            				Height="55"
            				d:LayoutOverrides="HorizontalAlignment"
            				Margin="0,6,0,0"
            				Width="60"
                            Style="{StaticResource Phone_CheckBoxStyle}"
                            MinWidth="0"
                            VerticalAlignment="Top"/>
                        <StackPanel Orientation="Vertical" Margin="0,9,0,0">
                            <StackPanel Orientation="Horizontal" Margin="0,0,0,-6" VerticalAlignment="Top">
                                <TextBlock
            						Text="{Binding Medication.Name}"
            						TextWrapping="Wrap" Margin="0" Style="{StaticResource PhoneTextTitle2Style}"/>
                                <Canvas 
            						x:Name="circlewithi" 
            						Height="18.484" 
            						Width="18.486" 
            						HorizontalAlignment="Left"
                                    Margin="5,5,-4,0">
                                    <Path Data="F1 M7349.5762,7576.0088 C7349.4844,7576.0356 7349.0132,7576.1387 7348.8774,7576.1587 C7348.7422,7576.1826 7348.6011,7576.1987 7348.457,7576.2129 C7348.311,7576.2246 7348.168,7576.2319 7348.0254,7576.2319 C7347.6831,7576.2319 7347.3931,7576.187 7347.1504,7576.0986 C7346.9082,7576.0088 7346.709,7575.8828 7346.5513,7575.7236 C7346.394,7575.564 7346.2773,7575.3716 7346.2031,7575.1509 C7346.1313,7574.9297 7346.0933,7574.687 7346.0933,7574.4209 C7346.0933,7574.3086 7346.0991,7574.1846 7346.1113,7574.0469 C7346.125,7573.9087 7346.1411,7573.7656 7346.1621,7573.6157 C7346.1812,7573.4678 7346.207,7573.313 7346.2344,7573.1577 C7346.2632,7573.0029 7347.25,7568.3428 7347.269,7568.2578 L7349.7134,7568.2578 L7348.7813,7572.6548 C7348.7422,7572.833 7348.6973,7573.0337 7348.6523,7573.2568 C7348.605,7573.479 7348.584,7573.6699 7348.584,7573.833 C7348.584,7574.0278 7348.644,7574.1626 7348.7651,7574.2378 C7348.8882,7574.3149 7349.0293,7574.3516 7349.186,7574.3516 C7349.3184,7574.3516 7349.8462,7574.2456 7349.959,7574.1987 C7349.8911,7574.5068 7349.8281,7574.8066 7349.7671,7575.106 C7349.7061,7575.4038 7349.6421,7575.7026 7349.5762,7576.0088 z" Fill="#FF666666" Stretch="Fill" Height="7.974" Canvas.Left="6.816" Canvas.Top="7.13" Width="3.866"/>
                                    <Path Data="F1 M7350.3711,7565.7354 C7350.3711,7565.9365 7350.332,7566.1133 7350.2559,7566.2725 C7350.1792,7566.4292 7350.0762,7566.5654 7349.9453,7566.6816 C7349.8799,7566.7397 7349.5752,7566.9131 7349.4883,7566.9443 C7349.312,7567.0044 7349.123,7567.0352 7348.9199,7567.0352 C7348.7251,7567.0352 7348.5459,7567.0063 7348.3799,7566.9473 C7348.2153,7566.8906 7348.0723,7566.8086 7347.9531,7566.7046 C7347.833,7566.5996 7347.7393,7566.4766 7347.6699,7566.3335 C7347.6011,7566.1904 7347.5669,7566.0342 7347.5669,7565.8682 C7347.5669,7565.6675 7347.603,7565.4893 7347.6782,7565.3335 C7347.752,7565.1743 7347.853,7565.0396 7347.9829,7564.9233 C7348.1133,7564.8105 7348.2671,7564.7222 7348.4463,7564.6602 C7348.624,7564.5996 7348.8169,7564.5693 7349.0249,7564.5693 C7349.2192,7564.5693 7349.3979,7564.5972 7349.5601,7564.6563 C7349.7251,7564.7144 7349.8652,7564.7964 7349.9839,7564.9004 C7350.103,7565.0054 7350.1992,7565.1294 7350.2671,7565.2715 C7350.3359,7565.4155 7350.3711,7565.5684 7350.3711,7565.7354 z" Fill="#FF666666" Height="2.466" Stretch="Fill" Canvas.Left="8.29" Canvas.Top="3.441" Width="2.804"/>
                                    <Path Data="F1 M7341.2773,7570.3711 C7341.2863,7574.3681,7344.5213,7577.6051,7348.5203,7577.6121 C7352.5213,7577.6051,7355.7563,7574.3681,7355.7633,7570.3711 C7355.7563,7566.3721,7352.5213,7563.1351,7348.5203,7563.1271 C7344.5213,7563.1351,7341.2863,7566.3721,7341.2773,7570.3711 M7339.2773,7570.3711 C7339.2793,7565.2651,7343.4163,7561.1281,7348.5203,7561.1281 C7353.6253,7561.1281,7357.7633,7565.2651,7357.7633,7570.3711 C7357.7633,7575.4751,7353.6253,7579.6121,7348.5203,7579.6121 C7343.4163,7579.6121,7339.2793,7575.4751,7339.2773,7570.3711" Fill="#FF666666" Stretch="Fill" Height="18.484" Width="18.486"/>
                                </Canvas>
                            </StackPanel>
                            <StackPanel
            					Orientation="Horizontal" Margin="0">
                                <TextBlock
            						Text="{Binding Medication.Dosage}"
            						TextWrapping="Wrap"
                                    Style="{StaticResource Phone_DosageTxt}"/>
                                <TextBlock
            						Text=" | "
                                    FontSize="16"
                                    Foreground="#FF888888"/>
                                <TextBlock
            						Text="{Binding Medication.DeliveryMethod}"
            						TextWrapping="Wrap"
                                    Style="{StaticResource Phone_DosageTxt}"/>
                                <TextBlock
                                    Text=" at "
                                    Visibility="{Binding TakenTimestamp, Converter={StaticResource Converter_NullToVisibility}}"
                                    Style="{StaticResource Phone_DosageTxt}"
                                    Foreground="White"/>
                                <TextBlock
                                    Text="{Binding TakenTimestamp, ConverterParameter=\{0:h:mm tt\}, Converter={StaticResource Converter_StringFormat}}"
                                    Visibility="{Binding TakenTimestamp, Converter={StaticResource Converter_NullToVisibility}}"
                                    Style="{StaticResource Phone_DosageTxt}"
                                    Foreground="White"/>
                            </StackPanel>
                            <StackPanel
                                Orientation="Horizontal"
                                Visibility="{Binding DataContext.IsMultiPerson, Converter={StaticResource Converter_BooleanToVisibilityInverted}, ElementName=LayoutRoot}">
                                <Rectangle
            						x:Name="ColorBand"
            						Fill="{Binding Person.ColorBand}"
            						HorizontalAlignment="Left"
            						Height="10"
            						Width="10"
            						VerticalAlignment="Top"
                                    StrokeThickness="0"
                                    Margin="0,13,5,0"/>
                                <TextBlock
            						Text="{Binding Person.Name}"
            						TextWrapping="Wrap"
            						Foreground="White"
                                    Style="{StaticResource Phone_DosageTxt}"
                                    VerticalAlignment="Top"/>
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                    <!-- checkbox, image, pill, (i) -->
                    <Path
            			Data="M0,87 L432,87"
            			Stretch="Fill"
            			UseLayoutRounding="False"
            			Margin="0,17,0,0"
            			Grid.ColumnSpan="2"
                        VerticalAlignment="Bottom"
                        Stroke="{StaticResource Phone_DashedLineBrush}"
                        Grid.Row="1"/>
                    <!-- dashed line -->
                </Grid>
            </Button>
        </DataTemplate>

        <DataTemplate x:Key="Local_GroupTemplate">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                	<RowDefinition />
                </Grid.RowDefinitions>
                <TextBlock
                    Text="{Binding Key, ConverterParameter=\{0:h:mm tt\}, Converter={StaticResource Converter_StringFormat}}"/>
                <ItemsControl
                    ItemsSource="{Binding Values}"
                    ItemTemplate="{StaticResource Local_ScheduleDayItemViewModelTemplate}"
                    Grid.Row="1"/>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
    	<i:Interaction.Triggers>
    		<pi:DataTrigger Binding="{Binding IsToday}" Value="False">
    			<pi:SetProperty PropertyName="Background" Value="#222222"/>
    		</pi:DataTrigger>
    	</i:Interaction.Triggers>
        <ScrollViewer
            BorderThickness="0"
            VerticalScrollBarVisibility="Hidden">
            <ItemsControl
                ItemsSource="{Binding GroupedDaySchedule}"
                ItemTemplate="{StaticResource Local_GroupTemplate}"
                Margin="20,0,30,0"/>
        </ScrollViewer>
    </Grid>
</UserControl>